package com.googlecode.sere.method

import com.googlecode.sere.http.{HttpResponse, Status}

trait MethodResponse extends HttpWritable {
  val statusCode: Status.Value
  def writeToHttpResponse(httpResponse: HttpResponse) {
    httpResponse.setStatus(statusCode.id)
  }
}

case class EmptyResponse(val statusCode: Status.Value) extends MethodResponse

case class EntityResponse(val statusCode: Status.Value, entity: String,
  etag: Option[String] = None) extends MethodResponse {

  override def writeToHttpResponse(httpResponse: HttpResponse) {
    super.writeToHttpResponse(httpResponse)
    httpResponse.setEntityContent(entity.getBytes)
    etag foreach { httpResponse.setHeader("ETag", _) }
  }
}

case class UriResponse(val statusCode: Status.Value, uri: String) extends MethodResponse {

  override def writeToHttpResponse(httpResponse: HttpResponse) {
    super.writeToHttpResponse(httpResponse)
    httpResponse.setHeader("Location", uri)
  }
}
